import request from '@/utils/axios'

export interface UserType {
  id: number
  username: string
  nickname: string
  deptId: number
  postIds: string[]
  email: string
  mobile: string
  sex: number
  avatar: string
  loginIp: string
  status: number
  remark: string
  loginDate: Date
  createTime: Date
}

/**
 * 用户接口
 */
export const UserApi = {
  // 新增用户
  create: (data: UserType) => {
    return request.post({ url: '/system/user/create', data, is_mock: true })
  },
  // 修改用户
  update: (data: UserType) => {
    return request.put({ url: '/system/user/update', data, is_mock: true })
  },
  // 用户状态修改
  updateStatus: (id: number, status: number) => {
    const data = {
      id,
      status
    }
    return request.put({ url: '/system/user/update-status', data, is_mock: true })
  },
  // 用户密码重置
  resetPwd: (id: number, password: string) => {
    const data = {
      id,
      password
    }
    return request.put({ url: '/system/user/update-password', data, is_mock: true })
  },
  // 删除用户
  delete: (id: number) => {
    return request.delete({ url: '/system/user/delete?id=' + id, is_mock: true })
  },
  // 查询用户详情
  detail: (id: number) => {
    return request.get({ url: '/system/user/get?id=' + id, is_mock: true })
  },
  // 查询用户管理列表
  page: (params: PageParam) => {
    return request.get({ url: '/system/user/page', params, is_mock: true })
  },
  // 查询所有用户列表
  all: () => {
    return request.get({ url: '/system/user/all', is_mock: true })
  },
  // 获取用户精简信息列表
  list: (): Promise<UserType[]> => {
    return request.get({ url: '/system/user/simple-list', is_mock: true })
  },
  // 导出用户
  export: params => {
    return request.download({ url: '/system/user/export', params, is_mock: true })
  },
  // 下载用户导入模板
  template: () => {
    return request.download({ url: '/system/user/get-import-template', is_mock: true })
  }
}
